package com.hs.spring.bean;

import com.hs.spring.bean.config.SpringConfiguration;
import com.hs.spring.bean.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author: songhao
 * @Date: 2021/9/5
 * @Description: TODO
 */
public class TestAssemblyBeans {

    @Test
    public void testBeanByXml(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
        System.out.println(applicationContext.getBean("user"));
    }

    @Test
    public void testBeanAnno(){
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
        UserService userService = (UserService)applicationContext.getBean("userService");
        System.out.println("登录状态:" + userService.login("admin","admin"));
    }
}
